package org.example.new_hbps_backend_reconstruction.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.example.new_hbps_backend_reconstruction.entity.StepCountLogsEntity;

import java.time.LocalDate;
import java.util.List;

/**
 * @author 丁利军
 * @date 2025年10月15日 20:26
 * @description 步数表的mapper
 */
@Mapper
public interface StepCountLogsMapper extends BaseMapper<StepCountLogsEntity> {
    // 1. 根据 patientUid 查找最新一条
    //@Select("SELECT * FROM step_count_logs WHERE patient_uid = #{patientUid} ORDER BY upload_time DESC LIMIT 1")
    StepCountLogsEntity findLatestByPatientUid(@Param("patientUid") Long patientUid);

    // 2. 根据 patientUid 分页查找
    IPage<StepCountLogsEntity> selectPageByPatientUid(Page<?> page, @Param("patientUid") Long patientUid);

    // 3. 根据 patientUid 和日期查找
//    @Select("SELECT * FROM step_count_logs " +
//            "WHERE patient_uid = #{patientUid} " +
//            "AND DATE(upload_time) = #{date} " +
//            "ORDER BY upload_time DESC")
    List<StepCountLogsEntity> findByPatientUidAndDate(@Param("patientUid") Long patientUid,
                                                      @Param("date") LocalDate date);

    // 4. 根据 patientUid 查找所有
    //@Select("SELECT * FROM step_count_logs WHERE patient_uid = #{patientUid} ORDER BY upload_time DESC")
    List<StepCountLogsEntity> findAllByPatientUid(@Param("patientUid") Long patientUid);
}

